#include "pageadmininfo.h"
#include "ui_pageadmininfo.h"
#include "adminloginform.h"
#include "mainbar.h"
#include <QDebug>

pageAdminInfo::pageAdminInfo(Mainbar *mainbar, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::pageAdminInfo),
    m_mainbar(mainbar)
{
    ui->setupUi(this);

    connect(m_mainbar, &Mainbar::sendUsername, this, &pageAdminInfo::receiveUsername);

    //连接点击btnGoLogin信号和发送display信号
    connect(ui->btnChangeInfo,&QPushButton::clicked,this,[=](){
        emit display(8);
        emit sendUsername(loginUsername);
    });
}

pageAdminInfo::~pageAdminInfo()
{
    delete ui;
}

void pageAdminInfo::receiveUsername(const QString& username)
{
    loginUsername = username;
    qDebug() << "收到用户名:" << loginUsername;
    userInfo = m_userMgr.queryUserByUsernamePhoneMail(loginUsername,"","");

    // 打印所有字段
    qDebug() << "用户信息字段：" << userInfo.keys();

    // 检查是否查询到用户信息
    if (!userInfo.isEmpty())  {
        ui->lineEditMail->setText(userInfo["email"].toString());
        ui->lineEditRole->setText(userInfo["role"].toString());
        ui->lineEditPhone->setText(userInfo["phone"].toString());
        ui->lineEditUserName->setText(loginUsername);
        ui->lineEditRegisterDate->setText(userInfo["created_at"].toString());
        ui->lineEditUpdateDate->setText(userInfo["updated_at"].toString());
    }
}
